<?php 
include("includes/code_admin.php");
if (isset($_GET['id'])) {$id = $_GET['id'];}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title><?php echo SITEURL; ?> Administrator</title>
<link href="style_admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script.js"></script>

</head>

<body>
<div id="container">
<table class="main" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header">
    <!-- header start -->
    <?php include("includes/header.php");?>
    <!-- header finish -->
    </td>
  </tr>
  <tr>
    <td class="middle">&nbsp;</td>
  </tr>
  <tr>
    <td>
    <!-- tepa start -->
<?php include("includes/tepa.php"); ?>
    <!-- tepa finish -->
    </td>
  </tr>
  <tr>
    <td>
    <!-- contant start -->
<table class="content" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td>
    <!-- right col -->
<div class="right_col">
<h3 class="title">Yangi Tovar Qo'shish</h3>
<? 
if(isset($_POST['send']))
{
 $cat = $_POST['cat'];
 $main = $_POST['main'];
 $title = trim($_POST['title']);
 $text = trim($_POST['text']);
 $price = $_POST['price']." ".$_POST['valuta'];
 $date = $_POST['date'];

 $title = addslashes($title);
 $text = addslashes($text);
 $price = addslashes($price);
/*tekshir*/
 	if(trim($cat) == '')
    {
      $error = ' Kategoriyani tanlang ';
    }
	else if(trim($title) == '')
    {
      $error = ' Sarlavhani yozing';
    }
    else if(trim($text) == '')
    {
       $error = ' Matn yozmadingiz!';
    }
	if($error == '')
    {
	/****** RASM YUKLASH KODI *****/
	include("includes/img_uploader.php");
	/***** RASM YUKLASH KODI TAMOM ******/
	
	$result = mysql_query("INSERT INTO data (cat, title, text, date, price, img_mini, img, img2, img3, custom) 
	VALUES('$cat', '$title', '$text', '$date', '$price', '$img_link_thumb', '$img_link', '$img_link2', '$img_link3', '$main')");
	 if($result =='true')
	 { 
	 echo "<p class='ok'>Malumot qo'shildi, OK. ... ".$yuklandi.$yuklandi2.$yuklandi3."</p>";
	 echo $yuklanmadi.$yuborilmadi.$yuborilmadi2.$yuborilmadi3;
	 echo "<br><center><a href = '". $_SERVER['PHP_SELF'] ."'><b>Yana tovar kiritish</b></a>";
	 }
	 else 
	 { 
	 echo "<p class='error'>DIQQAT! Afsuski Tovaringiz qo'shilmadi... Qayta kiriting yoki adminga xabar bering</p>"; 
	 }
	}
}

if(!isset($_POST['send']) || $error != '')
{
?>
<fieldset>
<legend style="color:#728D9E">Yangi tovar kiritish</legend>
<?php if($error) echo "<p class='error'>$error </p>"; ?>
<form name="myform" action="" method="post" enctype="multipart/form-data" onsubmit="return tekshir(this)">
<table width="600" border="0" cellspacing="7" cellpadding="3">
  <tr>
    <td width="100" class="r">Kategoriya</td>
    <td>
<select name="cat" style="width:200px;">
<option value="">-- Tanlang --</option>
<?  
$q = mysql_query("SELECT * FROM menu ORDER by sort DESC");
   while ( $r = mysql_fetch_assoc($q) ) {
   $m_a[$r['id']] = array('title' => $r['title'], 'parent' => $r['parent']);
   }

function menu($parent) {
   global $m_a;
   $h_c = false;
   foreach ($m_a as $k => $v ) {
   if ( $v['parent'] == $parent ) {
   if ( $h_c === false ) {
   $h_c = true;
   }

   if($v['parent']!= '0') { $belgi =  " -- "; }
   echo '<option value='.$k.'>'.$belgi.$v['title'].'</option>';

   menu($k);
   }
   }
}
menu(0);
?>
</select>
 &nbsp; 
<label><input name="main" type="checkbox" value="main" /> Bosh sahifada ham ko'rinsinmi</label>
    </td>
  </tr>
  <tr>
    <td  class="r">Sarlavha</td>
    <td><input type="text" name="title" size="50" value="<?=$title;?>"/></td>
  </tr>
  <tr>
    <td class="r">Text</td>
    <td><textarea name="text" cols="60" rows="8"><?=$text;?></textarea></td>
  </tr>
  <tr>
    <td class="r">Narx</td>
    <td><input type="text" name="price" size="20" maxlength="15" value="<?=$price;?>" onkeyup="return raqam(this);" onchange="return raqam(this);"/> <input name="valuta" type="text" value=" sum" size="5" maxlength="10" /></td>
  </tr>
  <tr>
    <td class="r">Foto</td>
    <td><input type="file" name="file" size="30" /></td>
  </tr>
  <tr bgcolor="#D9DCDF">
    <td height="65" class="r">Foto 2 <br />  Foto 3 
     </td>
    <td>
    <input type="file" name="file2" size="30" /><br />
	<input type="file" name="file3" size="30" />
    </td>
  </tr>
  <tr>
    <td class="r">Vaqt</td>
    <td>
    <input type="text" name="date" size="20" value="<?php echo date("d-F, Y") ?>"/>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="send" value=" Yuborish " /></td>
  </tr>
</table>
</form>
</fieldset>
<?php 
}
?>
</div>
	<!-- right col finish -->
    </td>
  </tr>
</table>


    <!-- contant finish -->
    </td>
  </tr>
</table>
<!-- futer start -->
<?php include("includes/futer.php"); ?>
<!-- futer finish -->
</div>
</body>
</html>
